Skip to content

feat(mcp): optional MCP OAuth for Claude-compatible connectors#59

Draft
ChrisCoder9000 wants to merge 70 commits intodevelopmentfrom
cursor/mcp-oauth-claude-c9d2
Draft

feat(mcp): optional MCP OAuth for Claude-compatible connectors#59
ChrisCoder9000 wants to merge 70 commits intodevelopmentfrom
cursor/mcp-oauth-claude-c9d2

Conversation

@ChrisCoder9000
Copy link
Copy Markdown
Contributor

Summary

This adds optional OAuth for the BrainAPI MCP HTTP service so MCP clients (including Claude’s remote MCP connector) can follow the MCP authorization spec: protected resource metadata, dynamic client registration, PKCE authorization code flow, and Authorization: Bearer access tokens.

When OAuth is disabled (default, no env vars), behavior stays the same: MCP accepts BrainPAT or Authorization: Bearer <brainpat> as today.

How to enable

Set MCP_OAUTH_ISSUER_URL to the public HTTPS base URL of the MCP service (same host/port as uvicorn, no path), for example https://mcp.example.com.

Optional:

  • MCP_RESOURCE_SERVER_URL: canonical MCP resource URL (defaults to {issuer}/mcp). Must match what clients send as the RFC 8707 resource parameter.
  • MCP_OAUTH_SCOPES: space-separated scopes (default brainapi).
  • MCP_OAUTH_ACCESS_TOKEN_TTL, MCP_OAUTH_REFRESH_TOKEN_TTL, MCP_OAUTH_AUTH_CODE_TTL: TTLs in seconds.
  • MCP_OAUTH_SERVICE_DOCUMENTATION_URL: URL for OAuth server metadata service_documentation.

User flow

  1. Client discovers metadata and registers (FastMCP built-in /.well-known/oauth-authorization-server, /register, /authorize, /token).
  2. After /authorize, the user is redirected to /mcp-oauth/consent to enter BrainPAT; on success an auth code is issued and the client exchanges it for tokens.
  3. MCP tools continue to use guard_brainpat: Bearer access tokens are mapped back to the BrainPAT supplied at consent.

Notes

  • Token and code storage is in-memory (single process); restarts invalidate sessions. A follow-up could persist codes/tokens in Redis if needed.
  • example-docker-compose.yaml documents the new env vars for the MCP service.
Open in Web Open in Cursor 

ChrisCoder9000 and others added 30 commits January 12, 2026 20:25
feat: add CRUD support for entities and relationships
Featured graph consolidation layer (5th agent)
improved neighbors retrieval
migrated neighbors into synergies
fix(neo4j): added safe parsing
fix(embeddings): logging error
build(Dockerfile): fixed poetry version
fix(Dockerfile): install poetry deps
ci(deps): added installation + import of spacy and other deps with po…
ChrisCoder9000 and others added 28 commits March 4, 2026 21:35
fix(retrieval): fixed missing brain_id relationships retrieval
fix(agent base): fixed many iterations and tool calls
fix(retrieval): text chunks retirieval
fix(files ingestion): dynamic webhook url from request
fix(doc ingestion): header url extraction
fix(build): added deps on container build time not startup anymore
feat(mcp): restricted to pat-only brains
fix(brain_id): mismatch between middleware and route args
chore(readme): updated layout
chore(readme): fixed context example
Enable MCP spec OAuth when MCP_OAUTH_ISSUER_URL is set: dynamic client
registration, protected resource metadata via FastMCP, consent page that
binds BrainPAT to opaque access tokens, and Bearer-to-PAT resolution for
existing tool authorization. Document env vars in example compose.

Co-authored-by: Christian <ChrisCoder9000@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 19, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dbcd9827-1857-40c2-ab66-7b873ce4b12d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/mcp-oauth-claude-c9d2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChrisCoder9000 ChrisCoder9000 changed the base branch from main to development April 19, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants